#include "Encoding/EncodingTask.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QUrl>
#include <QDebug>

EncodingTask::EncodingTask(const QMap<int, QString>& data) : data(data) {}

void EncodingTask::run()
{
    qDebug() << "EncodingTask running on thread" << QThread::currentThreadId();

    QJsonObject json;
    for (auto it = data.begin(); it != data.end(); ++it)
    {
        json[QString::number(it.key())] = it.value();
    }

    QJsonDocument doc(json);
    QByteArray encodedData = doc.toJson();

    QNetworkAccessManager* manager = new QNetworkAccessManager();
    QNetworkRequest request(QUrl("http://example.com/api/data"));
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
    manager->post(request, encodedData);

    qDebug() << "Encoded data sent:" << encodedData;
}
